package com.le.dub.controller;

import com.le.dub.common.Response;
import com.le.dub.service.IFileService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * @author guole
 * @created 2024/10/9
 */

@RestController
@RequestMapping("/file" )
public class FileController {
    @Resource
    private IFileService fileService;

    /**
     * 上传
     *
     * @return Ajaxresult转换结果
     */
    @RequestMapping(value = "/upload" )
    public Response upload(@RequestParam("file" ) MultipartFile file, @RequestParam("type" ) Integer type) throws IOException {

        String[] arr = file.getOriginalFilename().split("\\." );
        String suffix = arr[arr.length - 1];
        String path = fileService.upload(file.getBytes(), suffix, type);


        return Response.success(path);

    }

}
